package io.renren.modules.file.controller;

import java.util.Arrays;
import java.util.Map;

import io.renren.common.validator.ValidatorUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.renren.modules.file.entity.LocStoraEntity;
import io.renren.modules.file.service.LocStoraService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;



/**
 * 文件存储管理
 *
 * @author cheng
 * @email 751018031@qq.com
 * @date 2019-06-18 09:04:10
 */
@RestController
@RequestMapping("file/locstora")
public class LocStoraController {


    @Autowired
    private LocStoraService locStoraService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("file:locstora:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = locStoraService.queryPage(params);
        return R.ok().put("page", page);
    }

    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("file:locstora:info")
    public R info(@PathVariable("id") Integer id){
        LocStoraEntity locStora = locStoraService.getById(id);
        return R.ok().put("locStora", locStora);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("file:locstora:save")
    public R save(@RequestBody LocStoraEntity locStora){
        locStoraService.save(locStora);
        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("file:locstora:update")
    public R update(@RequestBody LocStoraEntity locStora){
        ValidatorUtils.validateEntity(locStora);
        locStoraService.updateById(locStora);
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("file:locstora:delete")
    public R delete(@RequestBody Integer[] ids){
        locStoraService.removeByIds(Arrays.asList(ids));
        return R.ok();
    }

}
